//
//  InfoCellView.m
//  LClass
//
//  Created by 严军 on 16/6/3.
//  Copyright © 2016年 YanJun. All rights reserved.
//

#import "InfoCellView.h"
@implementation InfoCellView
{
    UIButton* btnSelected;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

-(id)initWithData:(NSDictionary*)dic
{
    self=[super init];
    if (self) {
        _dataInfoDic=dic;
        self.backgroundColor=[UIColor whiteColor];
        [self layOut];
    }
    return self;
}

-(void)layOut
{
    
    //姓名
    UILabel* labName=[[UILabel alloc]init];
    _labName=labName;
    [self addSubview:labName];
    [labName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(8*SizeScal);
        make.centerX.equalTo(self);
        //make.width.equalTo(self.mas_width).dividedBy(2);
    }];
    labName.adjustsFontSizeToFitWidth=YES;
    labName.font=[UIFont boldSystemFontOfSize:SizeScal*50];
    labName.textColor=[UIColor colorWithRed:72.0/255 green:66/255.0 blue:184/255.0 alpha:1];//72 66 184
    labName.text=[_dataInfoDic objectForKey:@"studentName"];
    
    //学号
    UILabel* labStuNum=[[UILabel alloc]init];
    _labStuNum=labStuNum;
    [self addSubview:labStuNum];
    [labStuNum mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(labName.mas_bottom).offset(8*SizeScal);
        make.centerX.equalTo(self);
    }];
    labStuNum.font=[UIFont boldSystemFontOfSize:20*SizeScal];
    labStuNum.textColor=TitleColorLight;//72 66 184
    labStuNum.text=[_dataInfoDic objectForKey:@"stunumber"];
    
    //头像
    UIImageView* stuImg=[[UIImageView alloc]init];
    _stuImgView=stuImg;
    [self addSubview:stuImg];
    [stuImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(labStuNum.mas_bottom).offset(8*SizeScal);
        make.width.height.equalTo(self.mas_height).multipliedBy(0.25);
        make.left.mas_equalTo(10);
    }];
    [[Utility sharedInstance] setLayerView:stuImg borderW:1 borderColor:[UIColor colorWithWhite:0.7 alpha:0.5] radius:3];
    [stuImg setImage:[UIImage imageNamed:@"headImgDefault"]];
    
    //学院
    UILabel* lab1=[[UILabel alloc]init];
    [self addSubview:lab1];
    [lab1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(stuImg.mas_right).offset(15);
        make.top.equalTo(stuImg).offset(5);
    }];
    lab1.font=[UIFont systemFontOfSize:14*SizeScal];
    lab1.textColor=[UIColor darkGrayColor];
    lab1.text=@"学院:";
    
    UILabel* labCollege=[[UILabel alloc]init];
    _labCollege=labCollege;
    [self addSubview:labCollege];
    [labCollege mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(lab1.mas_right).offset(10);
        make.centerY.equalTo(lab1);
    }];
    labCollege.font=[UIFont systemFontOfSize:14*SizeScal];
    labCollege.textColor=[UIColor lightGrayColor];
    labCollege.text=[_dataInfoDic objectForKey:@"academyName"];
    //专业
    UILabel* lab2=[[UILabel alloc]init];
    [self addSubview:lab2];
    [lab2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(stuImg.mas_right).offset(15);
        make.centerY.equalTo(stuImg);
    }];
    lab2.font=[UIFont systemFontOfSize:14*SizeScal];
    lab2.textColor=[UIColor darkGrayColor];
    lab2.text=@"专业:";
    UILabel* labMajor=[[UILabel alloc]init];
    _labMajor=labMajor;
    [self addSubview:labMajor];
    [labMajor mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(lab2.mas_right).offset(10);
        make.centerY.equalTo(lab2);
    }];
    labMajor.font=[UIFont systemFontOfSize:14*SizeScal];
    labMajor.textColor=[UIColor lightGrayColor];
    labMajor.text=[_dataInfoDic objectForKey:@"professName"];
    
    //班级
    UILabel* lab3=[[UILabel alloc]init];
    [self addSubview:lab3];
    [lab3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(stuImg.mas_right).offset(15);
        make.bottom.equalTo(stuImg).offset(-5);
    }];
    lab3.font=[UIFont systemFontOfSize:14*SizeScal];
    lab3.textColor=[UIColor darkGrayColor];
    lab3.text=@"班级:";
    UILabel* labClass=[[UILabel alloc]init];
    _labClass=labClass;
    [self addSubview:labClass];
    [labClass mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(lab3.mas_right).offset(10);
        make.centerY.equalTo(lab3);
    }];
    labClass.font=[UIFont systemFontOfSize:14*SizeScal];
    labClass.textColor=[UIColor lightGrayColor];
    labClass.text=[_dataInfoDic objectForKey:@"className"];
    
    //三个考勤按钮
    for (int i=0; i<3; i++) {
        
        UIButton* btnKaoQin=[[UIButton alloc]init];
        [self addSubview:btnKaoQin];
        [btnKaoQin mas_makeConstraints:^(MASConstraintMaker *make) {
            make.height.width.equalTo(self.mas_width).multipliedBy(0.25);
            make.bottom.equalTo(self.mas_bottom).offset(-10*SizeScal);
            if (i==0) {
                make.left.equalTo(self).offset(15);
            }else if(i==1)
            {
                make.centerX.equalTo(self);
            }else
            {
                make.right.equalTo(self).offset(-15);
            }
            
        }];
        [[Utility sharedInstance]setLayerView:btnKaoQin borderW:1 borderColor:[UIColor colorWithWhite:0.8 alpha:0.5] radius:2];
        btnKaoQin.backgroundColor=ThemeBackgroundColor;
        [btnKaoQin setTitleColor:[UIColor darkGrayColor] forState:0];
         btnKaoQin.titleLabel.font=[UIFont boldSystemFontOfSize:18*SizeScal];
        btnKaoQin.tag=1000+i;
        [btnKaoQin addTarget:self action:@selector(clickKaoQin:) forControlEvents:UIControlEventTouchUpInside];
        if (i==0) {
            [btnKaoQin setTitle:@"到位" forState:0];
            btnKaoQin.selected=YES;
            btnSelected=btnKaoQin;
            [[Utility sharedInstance] setLayerView:btnKaoQin borderW:1 borderColor:TitleColorLight radius:2];
            [btnSelected setTitleColor:TitleColorLight forState:0];
        }else if(i==1)
        {
            [btnKaoQin setTitle:@"缺勤" forState:0];
        }else
        {
            [btnKaoQin setTitle:@"请假" forState:0];
        }
    }
    
}

-(void)clickKaoQin:(UIButton*)sender
{
    //1.取消选中状态
    btnSelected.selected=NO;
    [[Utility sharedInstance]setLayerView:btnSelected borderW:1 borderColor:[UIColor colorWithWhite:0.8 alpha:0.5] radius:2];
    [btnSelected setTitleColor:[UIColor darkGrayColor] forState:0];
    //2.设置选中状态
    sender.selected=YES;
    [[Utility sharedInstance]setLayerView:sender borderW:1 borderColor:TitleColorLight radius:2];
    [sender setTitleColor:TitleColorLight forState:0];
    //保存状态
    btnSelected=sender;
    int state=(int)sender.tag-1000+1;
    //返回考勤情况
    NSDictionary* parDic=@{@"state":[NSString stringWithFormat:@"%d",state],@"index":[NSString stringWithFormat:@"%d",_index]};
    _kaoQinBlock(parDic);
    
}


@end
